package com;

import javax.annotation.concurrent.GuardedBy;
import java.io.Closeable;

/**
 * @author 张述江
 * @date 2023-08-28
 */
public class ThreadInterruptor implements Closeable {
    private final Thread thread = Thread.currentThread();
    @GuardedBy("this")
    private boolean processing = true;

    ThreadInterruptor() {
    }

    public synchronized void interrupt() {
        if (this.processing) {
            this.thread.interrupt();
        }

    }

    @Override
    public synchronized void close() {
        this.processing = false;
        Thread.interrupted();
    }
}
